//
//  AppDelegate.swift
//  maste
//
//  Created by 帽子 on 2020/8/8.
//  Copyright © 2020 帽子. All rights reserved.
//  程序入口

import Cocoa
import SwiftUI

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
    func applicationDidFinishLaunching(_ aNotification: Notification) {
        let pasteboard = PasteboardUtil.shared
        pasteboard.startListening()
        pasteboard.onNewCopy { content in
            if content != UserData.pasteData[0].content {
                let item = PasteItem(id: NSUUID().uuidString, content: content, createTime: Date())
                UserData.pasteData.insert(item, at: 0)
                if !LocalCacheUtil.save(filename: UserData.historyFileName, value: UserData.pasteData) {
                    print("历史记录添加失败！")
                }
            }
        }
    }

    func applicationWillTerminate(_ aNotification: Notification) {
        // Insert code here to tear down your application
    }
}
